package com.chunuo.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chunuo.commonutils.R;
import com.chunuo.eduservice.controller.EduTeacherController;
import com.chunuo.eduservice.entity.EduCourse;
import com.chunuo.eduservice.entity.EduTeacher;
import com.chunuo.eduservice.service.EduCourseService;
import com.chunuo.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 类的作用
 *
 * @author liujiamiao
 * @email 2544296058@qq.com
 * @date 2020-07-25 14:01
 */
@RestController
@RequestMapping("/eduservice/teacherfront")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;

    //分页查询教师
    @GetMapping("/pageQeryTeacher/{page}/{limit}")
    public R pageQeryTeacher(@PathVariable("page")Long page,@PathVariable("limit")Long limit){
        Map<String, Object> map = eduTeacherService.pageQeryTeacher(new Page<EduTeacher>(page,limit));
        return R.ok().data(map);
    }

    //2 讲师详情的功能
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        //1 根据讲师id查询讲师基本信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        //2 根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> eduCourseList = eduCourseService.list(wrapper);
        return R.ok().data("eduTeacher",eduTeacher).data("eduCourseList",eduCourseList);
    }

}
